Passed
Push — main ( 492fd4...6428ec )
by Pieter Epeüs
02:19 queued 12s
created

intersect.js ➔ intersect   B

Complexity

Conditions 7

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 7

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 23
ccs 10
cts 10
cp 1
rs 8
c 0
b 0
f 0
cc 7
crap 7
1
export default function intersect(original, array, multi) {
2 4
    return original.filter((value) => {
3 12
        if (multi) {
4 6
            const found = array
5 12
                .map((item) => JSON.stringify(item))
6
                .reduce((accumulator, currentValue) => {
7 12
                    if (currentValue.indexOf(JSON.stringify(value)) >= 0) {
8 8
                        return accumulator + 1;
9
                    }
10
11 4
                    return accumulator;
12
                }, 0);
13
14 6
            return found === array.length;
15
        }
16
17 6
        return (
18
            array
19 18
                .map((item) => JSON.stringify(item))
20
                .indexOf(JSON.stringify(value)) >= 0
21
        );
22
    });
23
}
24